<template>
  <view class="mz-sidebar">
    <SidebarItem v-for="(item,index) in data" :key="index" :name="item.name" :active="activeIndex==index" @click="handClickItem(item,index)" />
    <slot></slot>
  </view>
</template>

<script>
import SidebarItem from "./SidebarItem.vue";
export default {
  components: {
    SidebarItem
  },
  props: {
    active: {
      type: Number,
      default: () => 0
    },
    data: {
      type: Array,
      default() {
        let item = {
          name: ""
        };
        return [];
      }
    }
  },
  data() {
    return {
      activeIndex: 0
    };
  },
  methods: {
    handClickItem(item, index) {
      this.activeIndex = index;
      this.$emit("change", item, index);
    }
  }
};
</script>

<style scoped lang="scss">
.mz-sidebar {
  // height: 100%;

  // background-color: $uni-bg-color-grey;

  .mz-sidebar_item {
    &.active {
      background-color: #ffffff;

      &::before {
        width: 3px;
        height: 100%;
        background-color: $uni-color-primary;
        position: absolute;
        left: 0;
      }
    }

    text-align: center;
    color: #000000;
    font-size: $uni-font-size-lg;
    padding: 15rpx 5rpx;
  }
}
</style>
